package com.jyuxuan.recruitment.mapper;

import com.jyuxuan.recruitment.pojo.Enterprise;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EnterpriseMapper {

    @Insert("Insert into enterprise(number,ename,code,type,organize,contacts,telephone,email,website,province,city,area,address,capital,license,state) values(#{number},#{ename},#{code},#{type},#{organize},#{contacts},#{telephone},#{email},#{website},#{province},#{city},#{area},#{address},#{capital},#{license},#{state})")
    public int save(Enterprise enterprise);

    @Update("Update enterprise set ename=#{ename},code=#{code},type=#{type}," +
            "organize=#{organize},contacts=#{contacts},telephone=#{telephone},email=#{email}," +
            "website=#{website},province=#{province},city=#{city},area=#{area},address=#{address}," +
            "capital=#{capital},license=#{license},state=#{state} where enterpriseId=#{enterpriseId}")
    public int update(Enterprise enterprise);

    @Select("Select * from enterprise where number=#{number}")
    public Enterprise findByNumber(String number);

    @Select("Select * from enterprise where enterpriseId=#{enterpriseId}")
    public Enterprise findByEnterpriseid(int enterpriseId);

    @Select({"<script>",
            "Select * from enterprise",
            "<where>",
            "<if test='code != null'> ",
            "and code=#{code} ",
            "</if>",
            "<if test='ename != null'> ",
            "and ename=#{ename} ",
            "</if>",
            "<if test='type != null'> ",
            "and type=#{type} ",
            "</if>",
            "<if test='organize != null'> ",
            "and organize=#{organize} ",
            "</if>",
            "<if test='province != null'> ",
            "and province=#{province} ",
            "</if>",
            "<if test='city != null'> ",
            "and city=#{city} ",
            "</if>",
            "<if test='area != null'> ",
            "and area=#{area} ",
            "</if>",
            "<if test='state != null'> ",
            "and state=#{state} ",
            "</if>",
            "</where>",
            "order by enterpriseId",
            "</script>"})
    public List<Enterprise> findDynamic(Enterprise enterprise);
}
